package com.read;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.read.utils.StringUtils;
import com.read.villager.dao.VillagerInfoDao;


public class Test {
	private static final Logger log = LoggerFactory.getLogger(Test.class);
	public static void main(String[] args) {
		/*File file = new File("/home/ksir/upload/nation/");
		if(!file.exists()){
			file.mkdirs();
		}
		log.debug(file.getAbsolutePath());*/
		/*NationPO na = new NationPO();
		na.setId("2");
		log.debug("");
		NationDao dao = new NationDao();
		dao.save(na);*/
		VillagerInfoDao vDao = new VillagerInfoDao();
		/*VillagerInfoPO p = new VillagerInfoPO();
		p.setName("ksir");
		p.setAge(20);
		p.setId("2");
		vDao.update(p);*/
		//List<VillagerInfoPO> list = vDao.getList();
		/*List<Map<String,Object>> lists = vDao.getMapList();
		log.info("excute result list:{}",JSON.toJSONString(lists));*/
		/*String test = "_insert_into_table_2";
		String s =StringUtils.toCamelCase(test);
		String b = StringUtils.toUnderlineName(s);
		log.info("替换结果:[{}],[{}]",s,b);*/
		
		int total = 100000;
		
		int i = 0;
		int j =0;
		int k = 0;
		
		BigDecimal total_per_big = new BigDecimal(total*((double)95)/100).setScale(0, BigDecimal.ROUND_HALF_UP);
		int total_per = total_per_big.intValue();
		int sum_per = 0;
		int eq = 0;
		int neq = 0;
		for(;i<total;i++){
			
			j=new Random().nextInt(total-i);
			k = total-i-j;
			BigDecimal big_i = new BigDecimal(i*(double)95/100).setScale(0, BigDecimal.ROUND_HALF_UP);
			BigDecimal big_j = new BigDecimal(j*(double)95/100).setScale(0, BigDecimal.ROUND_HALF_UP);
			BigDecimal big_k = new BigDecimal(k*(double)95/100).setScale(0, BigDecimal.ROUND_HALF_UP);
			int i2=big_i.intValue();
			int j2=big_j.intValue();
			int k2=big_k.intValue();
			//sum_per = Math.round(i2*95/100)+Math.round(j2*95/100)+Math.round(k2*95/100);
			sum_per = i2+j2+k2;
			if(total_per==sum_per){
				eq++;
			}else{
				neq++;
			}
			log.info("i={}-----j={}-----k={}-----total_per={}-----sum_per={}-----是否相等：{}",
					i,j,k,total_per,sum_per,total_per==sum_per);
		}
		log.info("总数据量：{}----相等次数：{} ----不相等次数{}",total,eq,neq);
		
	}
}
